package com.dys.testjdk17;

/**
 * @className: com.dys.testjdk17.SwitchTest
 * @description: JAVA17switch模式匹配
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/09/09 下午10:30
 */
public class SwitchTest {

    /**
     * 这是一个main()方法,是应用程序的入口
     *
     * @param args 方法的形参列表,是一个字符串数组,包含了从命令行传递给程序的参数
     */
    public static void main(String[] args) {
        testSwitch();
    }

    /**
     * switch模式匹配
     */
    private static void testSwitch() {
        int month = 12;
        String season = switch (month) {
            case 1, 12, 2:
                yield "冬季";
            case 3, 4, 5:
                yield "春季";
            case 6, 7, 8:
                yield "夏季";
            case 9, 10, 11:
                yield "秋季";
            default:
                yield "月份有误";
        };
        System.out.println(season);

        Object obj = "字符串";
        if (obj instanceof String str) {
            System.out.println(str);
        } else {
            System.out.println("非字符串......");
        }
    }

    /**
     * 模式匹配
     */
    private void methodA(A a) {
        // switch (a) {
        //     case B b -> System.out.println("B class");
        //     case C c -> System.out.println("C class");
        //     case D d -> System.out.println("D class");
        //     case E e -> System.out.println("E class");
        //     default -> System.out.println("other class");
        // }
    }
}

class A {
}

class B extends A {
}

class C extends A {
}

class D extends A {
}

class E extends A {
}
